package com.ljh.gmall.manage.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ljh.gmall.bean.PmsSkuInfo;
import com.ljh.gmall.service.SkuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author LJH
 * @date 2019/10/17 21:13
 */

@RestController
@CrossOrigin
public class SkuController {

    @Reference
    SkuService skuService;


    @PostMapping("saveSkuInfo")
    public String saveSkuInfo(@RequestBody PmsSkuInfo pmsSkuInfo){

        // 将spuId封装给productId
        pmsSkuInfo.setProductId(pmsSkuInfo.getSpuId());

        // 处理默认图片
        String skuDefaultImg = pmsSkuInfo.getSkuDefaultImg();
        if(StringUtils.isBlank(skuDefaultImg)){
            pmsSkuInfo.setSkuDefaultImg(pmsSkuInfo.getSkuImageList().get(0).getImgUrl());
        }


        String s=skuService.saveSkuInfo(pmsSkuInfo);

        return "s";
    }

}
